function getElementsByClassName(className, tag, elm){
  var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
  var tag = tag || "*";
  var elm = elm || document;
  var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
  var returnElements = [];
  var current;
  var length = elements.length;
  for(var i=0; i<length; i++){
    current = elements[i];
    if(testClass.test(current.className)){
      returnElements.push(current);
    }
  }
  return returnElements;
}

// ajax
function Inint_AJAX() {
  try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
  try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
  alert("XMLHttpRequest not supported");
  return null;
};

function retrieveURL(url,obj,position) {
  var req = Inint_AJAX();
  req.onreadystatechange = function () {
    if (req.readyState==4) {
      if (req.status==200) {
        var strResponseText = req.responseText;
        if(strResponseText){
          if(position == "after")
            document.getElementById(obj).innerHTML += strResponseText;
          if(position == "before")
            document.getElementById(obj).innerHTML = strResponseText+document.getElementById(obj).innerHTML;
          if(position == "replace")
            document.getElementById(obj).innerHTML = strResponseText;
          if(position == "value")
            document.getElementById(obj).value = strResponseText;
        }
      }
    }
  };

  req.open("GET", url ,true); //make connection
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
  req.send(null); //send value
}

function retrieveLongURL(url,pmeters,obj) {
  var req = Inint_AJAX();
  req.onreadystatechange = function () {
    if (req.readyState==4) {
      if (req.status==200) {
        var strResponseText = req.responseText;
        if(strResponseText)
          document.getElementById(obj).innerHTML = strResponseText; //retuen value
      }
    }
  };

  req.open('POST',url,true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req.setRequestHeader("Content-length", pmeters.length);
  req.setRequestHeader("Connection", "close");
  req.send(pmeters);
}

/*
retrieveOption(url, obj){
  var req = Inint_AJAX();
  req.onreadystatechange = function () {
    if (req.readyState==4) {
      if (req.status==200) {
        var strResponseText = req.responseText;
        if(strResponseText){

          var combo = document.getElementById(obj);
          combo.options.length = 0;

          var response = strResponseText;
          var items = response.split(";");
          var count = items.length;

          for (var i=0;i<count;i++) {
            var options = items[i].split(":");
            combo.options[i] = new Option(options[0],options[1]);
          }

          option = combo.getElementsByTagName("option");
          if(response == ""){
            combo.options[0] = new Option("Select Sub Category",0);
          }
        }
      }
    }
  };

  req.open("GET", url ,true); //make connection
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
  req.send(null); //send value
}
*/

function confirmSubmit(s){

  if(s == null){
    var agree=confirm("Are you sure?");
  }else{
    var agree=confirm(s);
  }

  if (agree){
    return true ;
  }
  else
    return false;
}


function upload(){
  window.open('../upload/upload-picture.php','upload_pic','width=700 , height=400, directories=no, resizable=no, menubar=no, location=no,scrollbars=yes, status=no');
}

function uploadProjectImg(id){
  window.open('../upload/upload-picture-project-img.php?project_id='+id,'upload_pic','width=700 , height=400, directories=no, resizable=no, menubar=no, location=no,scrollbars=yes, status=no');
}